<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>

<?php
if(  count( $this->live ) ):
    foreach( $this->live AS $live ) : 
        # Formattiamo campi
        list( $live['day'], $live['month'], $live['year'] )	    = explode( '-', $live['live_start_date'] );
        list( $live['live_start_time_h'], $live['live_start_time_m'] )  = explode( ':', $live['live_start_time'] );
        ?>
        <tr class="selectable <?php echo $this->selected == $live['live_id'] ? 'selected' : '' ?>" id="live_<?php echo $live['live_id'] ?>">
            <td class="date">
                <h3>
                    <b><?php echo $live['day'] ?>-<?php echo $this->months[$live['month']] ?>-<?php echo $live['year'] ?></b>
                    <span><?php //echo $this->days[date( 'N', mktime( $hour, $minute, $second, $live['month'], $live['day'], $live['year'] ) )]?></span>
                </h3>		
            </td>
            <td class="artists"><h3>
                <?php 
                $artists_list = '';
                if( count( $live['artists'] ) )
                {
                    foreach( $live['artists'] as $artist )
                    {
                        $artists_list .= $artist['artist_name'] .', ';
                    }
                }

                echo substr( $artists_list, 0, -2 );
                ?></h3>
            </td>
            <td class="location">
                <?php echo $live['location_name'] ?>
            </td>

            <td class="live-status">
<div class="live-status editable">
    <div class="live-actions" id="<?php echo $live['live_id'] ?>">
        <span class="<?php echo $this->live_status[$live['live_status_id']]['live_status_mark'] ?>"><?php echo $this->live_status[$live['live_status_id']]['live_status_name'] ?>
            <a class="edit-status" rel="live-status-options-<?php echo $live['live_id'] ?>">
                <img src="/images/admin/sort-default.png"/>
            </a>
        </span>
        <ul class="ddList" id="live-status-options-<?php echo $live['live_id'] ?>">
            <li><a rel="live-status-options-<?php echo $live['live_id'] ?>" class="dropup">Chiudi</a><h4>Cambia Stato</h4></li>
            <?php
            foreach( $this->live_status as $live_status ):
                ?>
            <li class="ddShow">
                <a href="javascript:void(0);" rel="{live_id: <?php echo $live['live_id']?>, live_status_id: <?php echo $live_status['live_status_id']?>}" class="select-status <?php echo $live_status['live_status_mark'] ?> <?php echo $live_status['live_status_id'] == $live['live_status_id'] ? 'selected' : ''?>"><?php echo $live_status['live_status_name'] ?></a>
            </li>
                <?php
            endforeach;
            ?>
        </ul>
    </div>
</div>
            </td>
            <td class="actions-mini" title="Operazioni">
                <span class="actions">
                    <a class="view" href="/admin/live/vedi/id/<?php echo $live['live_id'] ?>">&nbsp;</a>
                    <a class="edit" href="/admin/live/artisti/id/<?php echo $live['live_id'] ?>">&nbsp;</a>
                    <a class="del" href="">&nbsp;</a>
                </span>
            </td>                
        </tr>
<?php endforeach;
else:
    ?><tr class="result"><td colspan="5">Nessun elemento presente...</td></tr> <?php	
endif;?>
<tr>
    <td colspan="5">
        <script type="text/javascript">
            //<![CDATA[

            $(document).ready(function()
            {
                $("a.edit-status").click(function() {
                    $(".ddList").css('visibility', 'hidden');
                    $("#"+$(this).attr('rel')).css('visibility', 'visible');
                });

                $("div.live-actions a.dropup").click(function() {

                    $("#"+$(this).attr('rel')).css('visibility', 'hidden');	    
                });

                $("a.select-status").click(function() {
                    $.metadata.setType("attr", "rel");
                    console.log($(this).metadata().live_status);
                    
                    $.ajax({
                        url: "/admin/ajax/select/changelivestatus/id/",
                        type: "POST",
                        data: {
                          live_id : $(this).metadata().live_id,
                          live_status_id : $(this).metadata().live_status_id
                        },
                      cache: false,
                      success: function(html){
                        loadTab('#live');
                      },
                      error: function(jqXHR, textStatus) {
                          alert( "Request failed: " + textStatus );
                        }
                    });                    
                });
            });

            //]]>
        </script>
    </td>
</tr>